import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class ReplaceErrorWord {
    public static void main(String[] args) {
        String str = "忘记密码，不要惊慌失错，请登陆www.yy.cn或登陆www.tt,cc";
        String regex = "登陆";
        Pattern pattern =  Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        while(matcher.find()){
            String s = matcher.group();
            System.out.print(matcher.start()+"位置出现:");
            System.out.println(s);
        }
        System.out.println("讲\"登陆\"提换成\"登录\"的字符串");
        String result = matcher.replaceAll("登录");
        pattern = Pattern.compile("惊慌失错");
        matcher = pattern.matcher(result);
        System.out.println("讲\"惊慌失错\"提换成\"惊慌失措\"的字符串");
        result = matcher.replaceAll("惊慌失措");
        System.out.println(result);
    }
}
